'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:ContractGccontractCtrl
 * @description
 * # ContractGccontractCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('ContractGccontractCtrl', function ($scope, $location, $rootScope, openApi, Util, $routeParams, FormSubmit) {
        var id = $scope.process_id = $routeParams.id
        $scope.param = {};
        $scope.showprojectTypeObj = function () {
            var param = {};
            param.type = "工程类型";
            Util.getKeyValue(param, function (data) {
                $scope.projectTypelist = data.data
            })
        };
        $scope.choosePeople = function () {
            var relModuleObj = {
                name: "ContractGccontractCtrl",
                selectTab: "select_bid_by_contract",
                selectTabContent: "工程名称"
            };
            // 将列表的数据序列化存入缓存以便回来时候使用
            Util.savaParamForReview($scope.param, id);
            Util.savaDataforsearch(relModuleObj);
            $location.path("finance/choosepeople")
        };
        $scope.chooseCustomer = function () {
            var relModuleObj = {
                name: "ContractGccontractCtrl1",
                selectTab: "select_customer",
                selectTabContent: "合作伙伴"
            };
            // 清掉关联的编号
            Util.savaParamForReview($scope.param, id);
            Util.savaDataforsearch(relModuleObj);
            $location.path("finance/choosepeople")
        }
        $scope.submit = function (operationId) {

            // 底部类型end
            var options = {};
            // 流程id
            options.id = id;
            // 根据operationId判断是草稿还是提交
            options.operationId = operationId;
            options.urlParam = openApi.contractApply;
            options.param = angular.copy($scope.param, {});
            FormSubmit.submit(options,$scope);
        };
        $scope.validate = function () {
            if (!$scope.param.developer) {
                Util.Toast("请填写建筑单位");
                return;
            }
            if (!$scope.param.projectName) {
                Util.Toast("请填写工程名称");
                return;
            }
            if (!$scope.param.contractAmount) {
                if ($scope.param.contractAmount !== 0) {
                    Util.Toast("请填写合同金额");
                    return;
                }
            }
            if (!$scope.param.projectType) {
                Util.Toast("请选择工程类型");
                return;
            }
            if (!$scope.param.projectManager) {
                Util.Toast("请填写建造师");
                return;
            }
            if (!$scope.param.dateOfSigning) {
                Util.Toast("请选择合同签订日期");
                return;
            }
            if (!$scope.param.startWorkingDate) {
                Util.Toast("请选择计划起始日期");
                return;
            }
            if (!$scope.param.endWorkingDate) {
                Util.Toast("请选择计划竣工日期");
                return;
            }
            if (!$scope.validation.passvalidation) {
                Util.Toast($scope.validation.tip);
                return;
            }
            return true;
        }
        var init = function () {
            // 获取回显的详细信息
            Util.getDetailData(id, function (data) {
                $scope.param = data;
                $scope.disableInput = !!($scope.param && $scope.param.disableInput)
            });
            $scope.showprojectTypeObj()
        };
        // 初始化
        init();

    });
